<template>
    <view class="form-box">
      <u-navbar :is-back="false" :title="this.role == '2'?'宿舍卫生保洁':'宿舍安全检查'"></u-navbar>
      <view class="saoma-box" @click="clickFunc">
        <view class="saoma-box-inner">
          <image :src="`${proxyUrl}/static/saoma.png`"  style="width: 400rpx;height: 400rpx"></image>
          <p>点击按钮扫描 宿舍码 </p>
        </view>
      </view>
    </view>
</template>

<script>
import store from "@/store";
import { mapGetters } from "vuex";
import { getQueryString } from "@/utils/index.js";
import nuiPicker from "@/components/picker.vue";
import { getUrlParam } from "@/utils";
import {isEmpty} from "../../../utils";
export default {
    data() {
        return {
          role:'',
          proxyUrl:(window.location.href.includes('/xsdcrm-wechat-ui/')?'/xsdcrm-wechat-ui/': ''),
        };
    },

    onLoad(option) {
        this.role = option.role
        if (!this.role) {
          uni.showToast({title: '当前角色异常，请联系管理员',icon:'none'})
        }
    },
    mounted() {

    },
    methods: {
      clickFunc() {
        jWeixin.scanQRCode({
          needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
          scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码，默认二者都有
          success: (res) => {
            //扫码返回的结果
            let data_code = res.resultStr
            let str = data_code;
            let cleanedUrl = str.replace(/%22%7D%7D$/, '');  // 清理结尾的非法字符
            let match = cleanedUrl.match(/[?&]id=([^&]+)/);
            if (match) {
              let dormitoryId = match[1];
              console.log(dormitoryId); // 输出 "1"
              if (this.role == 2) {
                uni.navigateTo({
                  url: `/pages/serve/cleaning/webIndex?dormitoryId=${dormitoryId}`
                })
              } else if (this.role == 3){
                uni.navigateTo({
                  url: `/pages/serve/inspection/webIndex?dormitoryId=${dormitoryId}`
                })
              }

            } else {
              console.log("未找到匹配的参数值");
              uni.showToast({
                title: "未查询到宿舍信息",
                icon: "none",
              });
            }
          },
          cancel: () => {

          },
        });
      }
    },
};
</script>

<style lang="scss" scoped>
.form-box{
  height:calc(100vh - 0px);
  background: #f5f5f5;
}
    .saoma-box{
      display: flex;
      justify-content: center;
      align-items: center;
      height: 80vh;
      p{
        padding-top: 20rpx;
        font-size: 36rpx;
        color: red;
        text-align: center;
      }
      .saoma-box-inner{
        background: #FFFFFF;
        border: 1px solid #dddddd;
        padding: 60rpx;
        border-radius: 30rpx;
      }
    }
</style>
